package com.gljx.web.service.impl;

import com.gljx.web.Entity.Recordin;
import com.gljx.web.Entity.Recordinentry;
import com.gljx.web.Entity.Student;
import com.gljx.web.dao.RecordinMapper;
import com.gljx.web.dao.RecordinentryMapper;
import com.gljx.web.dao.StudentMapper;
import com.gljx.web.service.RecordinentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/7 0007.
 */
@Service
public class RecordinentryServiceImpl implements RecordinentryService {

    @Autowired
    StudentMapper studentMapper;
    @Autowired
    RecordinMapper recordinMapper;
    @Autowired
    private RecordinentryMapper recordinentryMapper;

    /**
     * @Author lcx
     * @Date 2017/11/7 0007 下午 1:39
     * 根据fid查询
     */
    @Override
    public List<Recordinentry> selectRecordinentryByFid(String fid, String name) {
        return recordinentryMapper.selectRecordinentryByFparentid(fid, name);
    }

    /**
     * @Author lcx
     * @Date 2017/11/9 0009 下午 4:10
     * 更新
     */
    @Override
    public void updateRecordinentry(Recordinentry recordinentry) {
        recordinentryMapper.updateByPrimaryKeySelective(recordinentry);
    }

    /**
     * @Author lcx
     * @Date 2017/11/10 0010 上午 10:56
     * 调用存储过程查询学生信息
     */
    @Override
    public void selectStudent() {

    }

    /**
     * @Author lcx
     * @Date 2017/11/11 0011 上午 10:10\
     * 更具id查询学生
     */
    @Override
    public Student selectStudentById(String id) {
        return studentMapper.selectStudentById(id);
    }

    @Override
    public List<Student> selectStudentByIdAsCflcsjidAndKemu(String id, String cflcsjid, String kemu) {
        return studentMapper.selectStudentByIdAsCflcsjidAndKemu(id, cflcsjid, kemu);
    }

    @Override
    public List<Student> selectStudentByIdAsCfbilltype(String id, String cfbilltype) {
        return studentMapper.selectStudentByIdAsyjj(id, cfbilltype);
    }

    @Override
    public void addRecordinentry(Recordinentry recordinentry) {
        recordinentryMapper.insertSelective(recordinentry);
        //更新学生表的信息
        Student student = new Student();
        student.setFid(recordinentry.getCfstudentid());//学员编号
        student.setCfjsybh(recordinentry.getCfjyzbh());//结业证编号
        student.setCfcfwz(recordinentry.getCfcfwz());//结业时间
        studentMapper.updateStudent(student);

    }

    /**
     * @Author lcx
     * @Date 2018/1/4 0004 下午 3:22
     * 搜索子类学生并且查询主表
     */
    @Override
    public List<Recordin> selectRecordinentryByName(String name) {
        List<Recordin> recordinList = new ArrayList<>();
        String[] fparentid = recordinentryMapper.selectRecordingByName(name);
        for (String fpid : fparentid) {
            Recordin recordin = recordinMapper.selectByPrimaryKey(fpid);
            recordinList.add(recordin);
        }
        return recordinList;
    }
}
